#include "voluecontrol.h"

#include <QPen>
#include <QBrush>
#include <QColor>

VolueControl::VolueControl(QWidget *parent) :
    QWidget(parent)
{
    m_val = 0;
}


void VolueControl::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    m_paint.begin(this);
    m_paint.setRenderHint(QPainter::Antialiasing);
    m_paint.setPen(QPen(Qt::NoPen));
    m_paint.setBrush(QBrush(QColor(27, 93, 178, 255)));
    QRectF rect(0.0, 0.0, this->width(), 15.0);
    m_paint.drawRoundedRect(rect,15,15);
    m_paint.setBrush(QBrush(QColor(255, 255, 255, 255)));
    float percent = (m_val)/20.0;
    QRectF valrect(0.0, 0.0,(int)(rect.width()*percent),rect.height());
    m_paint.drawRoundedRect(valrect,8.0,8.0);
    m_paint.end();
}

void VolueControl::setValue(int v)
{
   m_val = v;
   update();
}
